package com.sanyang.pda.ui.set;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.config.BaseUrl;
import com.wangshen.base.net.client.KRetrofitConfig;
import com.wangshen.base.net.client.KRetrofitFactory;
import com.wangshen.base.net.interceptor.ExCookieInterceptor;
import com.wangshen.base.ui.mvp.base.ui.BaseActivity;
import com.wangshen.base.util.SharedPreferencesUtil;
import com.wangshen.base.util.ToastUtils;
import com.wangshen.projectbase.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
@Route(path = AppActivityKey.SETACTIVITY)
public class SetActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.title)
    FrameLayout title;
    @BindView(R.id.et_ip)
    EditText etIp;
    @BindView(R.id.tv_lssue)
    TextView tvLssue;

    @Override
    public int getView() {
        return R.layout.activity_set;
    }

    @Override
    public void initView() {
        etIp.setText(SharedPreferencesUtil.getInstance().getString("ip", ""));
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {

    }



    @OnClick({R.id.iv_back, R.id.tv_lssue})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_lssue:
                if (TextUtils.isEmpty(etIp.getText())){
                    ToastUtils.showToast(mContext,"服务器地址不能为空！");
                    return;
                }
                BaseUrl.BASEURL = "http://" + etIp.getText().toString() /*+ ":50902/"*/;
                KRetrofitConfig config = new KRetrofitConfig.Builder()
                        .baseUrl(BaseUrl.BASEURL)
                        .retryOnConnectionFailure(false)
                        .setConnectTimeout(20)
                        .setReadTimeout(20)
                        .setWriteTimeout(20)
                        .addInterceptor(new ExCookieInterceptor())
                        .build();
                KRetrofitFactory.init(config);
                SharedPreferencesUtil.getInstance().putString("ip",etIp.getText().toString());
                ToastUtils.showToast(mContext,"设置成功！");
                finish();
                break;
        }
    }
}
